package cn.edu.cdut.controller;

import cn.edu.cdut.dto.MyRes;
import cn.edu.cdut.model.ResultInfo;
import cn.edu.cdut.service.DistributeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

/**
 * Author  kobe
 * Created on 2017-06-02-12:02
 */
@RestController
public class DistributeController {

        @Autowired
        private DistributeService distributeService;

        //分流
        @GetMapping("/specDistribute")
        public MyRes specDistribute() {
                try {
                        distributeService.specDistribute();
                }catch (Exception e) {
                        return new MyRes(201, "分流失败！", null);
                }
                return new MyRes(200, "分流完毕！", null);
        }

        //查询所有结果
        @GetMapping("/getAllResult")
        public MyRes getAllResult() {
                return distributeService.getAllResult();
        }

        //修改结果
        @PostMapping("/updateResult")
        public MyRes updateResult(@RequestBody ResultInfo resultInfo, BindingResult bindingResult) {
                if (bindingResult.hasErrors()) {
                        return new MyRes(201, "提交失败！", null);
                }
                return distributeService.updateResult(resultInfo);
        }

        //查询一个结果
        @GetMapping("/getResult")
        public MyRes getResult(@RequestParam("stuId") String stuId) {
                return distributeService.getResult(stuId);
        }
}
